package com.examination.mlib.utils;

import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;

import com.alibaba.android.arouter.launcher.ARouter;
import com.examination.mlib.constants.ARouterConstants;
import com.examination.mlib.constants.KitArouterConstants;
import com.examination.mlib.constants.UserInfoConstants;
import com.examination.mlib.interfaceapi.HomeBackApi;
import com.yilijk.base.utils.SharedPreferencesUtils;

public class SchemeUtil {
    public static final String SCHEME = "com.patient.scheme";
    public static final String HOST_CMS = "cms";
    public static final String HOST_URL = "url";

    //    com.patient.scheme://cms?load=xxxx
//    com.patient.scheme://url?load=xxxx
    public static void navigation(Context context, String uriStr) {
        Uri uri = Uri.parse(uriStr);
        if (SCHEME.equals(uri.getScheme())) {
            String host = uri.getHost();
            String load = uri.getQueryParameter("load");
            switch (host) {
                case HOST_CMS: {
                    if (!TextUtils.isEmpty(load)) {
                        Bundle bundle = new Bundle();
                        bundle.putString("promotionId", load);
                        HomeBackApi homeBackApi = (HomeBackApi) ARouter.getInstance().build(ARouterConstants.HomeModuleImpl).navigation();
                        homeBackApi.Android2RnPush(context, KitArouterConstants.CART_DOCTORBUNDLE, KitArouterConstants.Cart.Promotion, bundle);
                    }
                    break;
                }
                case HOST_URL: {
                    if (!TextUtils.isEmpty(load) && (load.startsWith("http") || load.startsWith("https"))) {
                        String passportId = SharedPreferencesUtils.getInstance().getString(UserInfoConstants.account_passportId, "");
                        String token = SharedPreferencesUtils.getInstance().getString(UserInfoConstants.token, "");
                        String url = load.replace("${passportId}", passportId + "");
                        url = url.replace("${token}", token + "");
                        ARouter.getInstance().build(ARouterConstants.MineWebviewActivity)
//                                                            .withString("title", bannerBean.getTitle())
                                .withBoolean("ishtml", false)
                                .withString("url", url)
                                .withBoolean("isShowLoading", true).navigation();
                    }
                    break;
                }
            }
        }
    }
}
